package com.sky.mapper;

import com.sky.entity.SetmealDish;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SetmealDishMapper {

    /**
     * 获得有关联套餐的菜品id列表
     * @param ids
     * @return
     */
    List<Long> countByDishId(List<Long> ids);

    /**
     * 根据套餐id查询详细菜品
     * @param id
     * @return
     */
    @Select("select sd.name, sd.copies, d.image, d.description " +
            "from setmeal_dish sd, dish d " +
            "where sd.dish_id = d.id and setmeal_id = #{id}")
    List<DishItemVO> getDishItemVOBySetmealId(Long id);

    /**
     * 通过套餐id获得简要菜品信息
     * @param id
     * @return
     */
    @Select("select * from setmeal_dish where setmeal_id = #{id}")
    List<SetmealDish> getSetmealDishBySetmealId(Long id);

    /**
     * 给setmeal_dish插入数据
     * @param setmealDishes
     */
    @Insert("insert into setmeal_dish(setmeal_id, dish_id, name, price, copies)" +
            " VALUES(#{setmealId}, #{dishId}, #{name}, #{price}, #{copies}) ")
    void addSetmealDish(SetmealDish setmealDishes);

    /**
     * 通过id列表批量删除数据
     * @param id
     */
    @Delete("delete from setmeal_dish where setmeal_id = #{id}")
    void deleteSetmealDish(Long id);
}
